﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SpeakOut.Lib
{
    public static class DateTimeExtensionMethods
    {
        public static bool EqualsIgnoreDay(this DateTime? date1, DateTime? date2)
        {
            //if either date is null the equality is false
            if (date1.HasValue.Not() || date2.HasValue.Not()) return false;
            return EqualsIgnoreDay(date1.Value, date2.Value);
        }

        public static bool EqualsIgnoreDay(this DateTime date1, DateTime date2)
        {
            return EqualsIgnoreDay(date1, date2.Year, date2.Month);
        }

        public static bool EqualsIgnoreDay(this DateTime date, int year, int month)
        {
            return date.Month == month && date.Year == year;
        }

        public static DateTime FirstDayOfMonth(this DateTime date)
        {
            return new DateTime(date.Year, date.Month, 1);
        }

        public static DateTime LastDayOfMoth(this DateTime date)
        {
            return date.FirstDayOfMonth().AddMonths(1).AddDays(-1);
        }
    }
}
